{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "from lxml import html\n",
    "import re\n",
    "from fontTools.ttLib import TTFont"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = {\n",
    "            \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\n",
    "            \"Accept-Encoding\": \"gzip, deflate, br\",\n",
    "            \"Accept-Language\": \"zh-CN,zh;q=0.8\",\n",
    "            \"Cache-Control\": \"max-age=0\",\n",
    "            \"Connection\": \"keep-alive\",\n",
    "            \"Upgrade-Insecure-Requests\": \"1\",\n",
    "            \"Content-Type\": \"application/x-www-form-urlencoded; charset=UTF-8\",\n",
    "            \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36\"\n",
    "        }\n",
    "url = \"https://club.autohome.com.cn/bbs/thread-c-2778-69436529-1.html\"\n",
    "host = {'host':'club.autohome.com.cn','cookie':'your cookie'}\n",
    "headers = {\n",
    "            \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\n",
    "            \"Accept-Encoding\": \"gzip, deflate, br\",\n",
    "            \"Accept-Language\": \"zh-CN,zh;q=0.8\",\n",
    "            \"Cache-Control\": \"max-age=0\",\n",
    "            \"Connection\": \"keep-alive\",\n",
    "            \"Upgrade-Insecure-Requests\": \"1\",\n",
    "            \"Content-Type\": \"application/x-www-form-urlencoded; charset=UTF-8\",\n",
    "            \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36\",\n",
    "            'host':'club.autohome.com.cn',\n",
    "            'cookie':'your cookie'\n",
    "          }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.get(url, headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = html.fromstring(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "cmp = re.compile(\",url\\('(//.*.ttf)'\\) format\\('woff'\\)\")\n",
    "rst = cmp.findall(r.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['//k3.autoimg.cn/g1/M08/D2/D1/ChcCQ1sUz2OAeAubAABj8El3-6U87..ttf']"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rst#取出url链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "ttf = requests.get(\"http:\" + rst[0], stream=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(\"autohome.ttf\", \"wb\") as pdf:\n",
    "    for chunk in ttf.iter_content(chunk_size=1024):\n",
    "        if chunk:\n",
    "            pdf.write(chunk)\n",
    "            \n",
    "#把待破解的文字写到文件中去"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "font = TTFont('autohome.ttf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "uniList = font['cmap'].tables[0].ttFont.getGlyphOrder()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['.notdef',\n",
       " 'uniEC3A',\n",
       " 'uniED7B',\n",
       " 'uniEDCD',\n",
       " 'uniED19',\n",
       " 'uniEC66',\n",
       " 'uniECB8',\n",
       " 'uniEDF8',\n",
       " 'uniEC56',\n",
       " 'uniED97',\n",
       " 'uniECE3',\n",
       " 'uniED35',\n",
       " 'uniEC82',\n",
       " 'uniEDC2',\n",
       " 'uniEC20',\n",
       " 'uniED61',\n",
       " 'uniEDB3',\n",
       " 'uniECFF',\n",
       " 'uniEC4C',\n",
       " 'uniEC9E',\n",
       " 'uniEDDE',\n",
       " 'uniED2B',\n",
       " 'uniED7D',\n",
       " 'uniECC9',\n",
       " 'uniED1B',\n",
       " 'uniEC68',\n",
       " 'uniEDA8',\n",
       " 'uniEDFA',\n",
       " 'uniED47',\n",
       " 'uniEC93',\n",
       " 'uniECE5',\n",
       " 'uniEC32',\n",
       " 'uniEC83',\n",
       " 'uniEDC4',\n",
       " 'uniED11',\n",
       " 'uniED62',\n",
       " 'uniECAF',\n",
       " 'uniEDF0',\n",
       " 'uniEC4D']"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "uniList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
